/**
 * SIX VULN - http://code.google.com/p/six-vuln/
 * Copyright (C) 2006
 *   National Institute of Advanced Industrial Science and Technology (AIST)
 *   Registration Number: H20PRO-863
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.go.aist.six.vuln.model.scap.vulnerability;

import java.io.Serializable;
import jp.go.aist.six.vuln.model.scap.core.NotesType;
import jp.go.aist.six.vuln.model.scap.core.ReferenceType;




/**
 * Extends the base Reference class by adding the ability
 * to specify which kind (within the vulnerability model) of reference it is.
 * See "VulnerabilityReferenceCategoryList" enumeration.
 *
 * @author	Akihito Nakamura, AIST
 * @version $Id: VulnerabilityReferenceType.java 529 2013-04-15 07:08:54Z nakamura5akihito@gmail.com $
 */
public class VulnerabilityReferenceType
    implements Serializable
{

    private String  source;
    //{0..1}

    private ReferenceType  reference;
    //{1..1}

    private NotesType  notes;
    //{0..1}

    public static final String  DEFAULT_LANG = "en";
    private String  lang;
    //{optional, default="en"}

    private VulnerabilityReferenceCategoryEnumType  referenceType;
    //{required}

    private Boolean  deprecated;
    //{optional}



    /**
     * Constructs an instance.
     */
    public VulnerabilityReferenceType()
    {
    }



    /**
     */
    public String getSource()
    {
        return source;
    }


    public void setSource(
                    final String source
                    )
    {
        this.source = source;
    }



    /**
     */
    public ReferenceType getReference()
    {
        return reference;
    }


    public void setReference(
                    final ReferenceType reference
                    )
    {
        this.reference = reference;
    }


    /**
     */
    public NotesType getNotes()
    {
        return notes;
    }


    public void setNotes(
                    final NotesType notes
                    )
    {
        this.notes = notes;
    }


    /**
     */
    public void setLang(
                    final String lang
                    )
    {
        this.lang = lang;
    }


    public String getLang()
    {
        return lang;
    }


    public static String lang(
                    final VulnerabilityReferenceType vulnerabilityReference
                    )
    {
        if (vulnerabilityReference == null) {
            throw new IllegalArgumentException( "null vulnerabilityReference" );
        }

        final String  lang = vulnerabilityReference.getLang();
        return (lang == null ? DEFAULT_LANG : lang);
    }



    /**
     */
    public VulnerabilityReferenceCategoryEnumType getReferenceType()
    {
        return referenceType;
    }


    public void setReferenceType(
                    final VulnerabilityReferenceCategoryEnumType referenceType
                    )
    {
        this.referenceType = referenceType;
    }



    /**
     */
    public Boolean isDeprecated()
    {
        return deprecated;
    }


    public void setDeprecated(
                    final Boolean deprecated
                    )
    {
        this.deprecated = deprecated;
    }



    //*********************************************************************
    //  java.lang.Object
    //*********************************************************************

    @Override
    public int hashCode()
    {
        final int  prime = 37;
        int  result = 17;

        final String  source = getSource();
        final ReferenceType  reference = getReference();
        final NotesType  notes = getNotes();
        final String  lang = lang( this );
        final VulnerabilityReferenceCategoryEnumType  referenceType = getReferenceType();
        final Boolean  deprecated = isDeprecated();

        result = prime * result + ((source == null) ? 0 : source.hashCode());
        result = prime * result + ((reference == null) ? 0 : reference.hashCode());
        result = prime * result + ((notes == null) ? 0 : notes.hashCode());
        result = prime * result + ((lang == null) ? 0 : lang.hashCode());
        result = prime * result + ((referenceType == null) ? 0 : referenceType.hashCode());
        result = prime * result + ((deprecated == null) ? 0 : deprecated.hashCode());

        return result;
    }



    @Override
    public boolean equals(
                    final Object obj
                    )
    {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof VulnerabilityReferenceType)) {
            return false;
        }

        VulnerabilityReferenceType  other = VulnerabilityReferenceType.class.cast( obj );
        final String   this_source =  this.getSource();
        final String  other_source = other.getSource();
        if (this_source == other_source
                        ||  (this_source != null  &&  this_source.equals( other_source ))) {
            final ReferenceType   this_reference =  this.getReference();
            final ReferenceType  other_reference = other.getReference();
            if (this_reference == other_reference
                            ||  (this_reference != null  &&  this_reference.equals( other_reference ))) {
                final NotesType   this_notes =  this.getNotes();
                final NotesType  other_notes = other.getNotes();
                if (this_notes == other_notes
                                ||  (this_notes != null  &&  this_notes.equals( other_notes ))) {
                    final String   this_lang = lang( this );
                    final String  other_lang = lang( other );
                    if (this_lang == other_lang
                                    ||  (this_lang != null  &&  this_lang.equals( other_lang ))) {
                        if (this.getReferenceType() == other.getReferenceType()) {
                            if (this.isDeprecated() == other.isDeprecated()) {
                                return true;
                            }
                        }
                    }
                }
            }
        }

        return false;
    }



    @Override
    public String toString()
    {
        return "VulnerabilityReferenceType[source=" + getSource()
                        + ", reference="        + getReference()
                        + ", notes="            + getNotes()
                        + ", lang="             + getLang()
                        + ", referenceType="    + getReferenceType()
                        + ", deprecated="       + isDeprecated()
                        + "]";
    }

}
//VulnerabilityReferenceType
